import 'dart:io';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:image_picker/image_picker.dart';
import 'package:test01/okhttp_test/pojo/commentdto_pojo.dart';
import 'package:test01/okhttp_test/util/request_http.dart';


/*
*
* 获取本地图片
*
* */

void main() => runApp(
  MyApp(),
);


class MyApp extends StatefulWidget {
  const MyApp({Key key}) : super(key: key);

  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    ///禁止程序横屏
    SystemChrome.setPreferredOrientations([
      DeviceOrientation.portraitUp, //只能纵向
      DeviceOrientation.portraitDown, //只能纵向
    ]);

    return MaterialApp(
      home: ObtainPicturePage(),
    );
  }
}

///第三方插件获取本地资源相册--本地相机拍照
class ObtainPicturePage extends StatefulWidget {
  const ObtainPicturePage({Key key}) : super(key: key);

  @override
  _ObtainPicturePageState createState() => _ObtainPicturePageState();
}

class _ObtainPicturePageState extends State<ObtainPicturePage> {
  var _imgPath;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text("ImagePicker"),
        ),
        body: SingleChildScrollView(
          child: Column(
            children: <Widget>[
              _ImageView(_imgPath),
              RaisedButton(
                onPressed: _takePhoto,
                child: Text("拍照"),
              ),
              RaisedButton(
                onPressed: _openGallery,
                child: Text("选择照片"),
              ),
            ],
          ),
        ));
  }

  /*图片控件*/
  Widget _ImageView(imgPath) {
    if (imgPath == null) {
      return Center(
        child: Text("请选择图片或拍照"),
      );
    } else {
      return Image.file(
        imgPath,
      );
    }
  }


  /*拍照*/
  _takePhoto() async {
    var image = await ImagePicker().getImage(source: ImageSource.camera);
    setState(() {
      _imgPath = image;
    });
  }

  /*相册*/
  _openGallery() async {
    final pickedFile = await ImagePicker().getImage(source: ImageSource.gallery);
    final File image = File(pickedFile.path);
    setState(() {
      _imgPath = image;
      print("-------------------获取的图片路径$_imgPath----------------------");
    });
  }
}



class HeadPicturePage extends StatefulWidget {
  const HeadPicturePage({Key key}) : super(key: key);

  @override
  _HeadPicturePageState createState() => _HeadPicturePageState();
}

class _HeadPicturePageState extends State<HeadPicturePage> {
  ///获取网络对象
  CommentDto commentDto=CommentDto();
  ///获取网络url
  String picUrl;
  ///获取图片
  List <PicUrls> picUrlList=[];

  @override
  void initState() {
   aaa();
    super.initState();
  }


  ///初始化数据
  aaa() async{
    tokens="bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOjEwMDQw"
        "NzEsInVzZXJfbmFtZSI6IjEwMDQwNzEiLCJzY29wZSI6WyJhcHB1c2VyIiwidWN"
        "lbnRlciIsInVhYSIsInRoaXJkIiwidGVybWluYWwiLCJzcG9ydCIsImVzIiwiYW"
        "dvcmEiXSwiaXNQaG9uZSI6MSwiaXNQZXJmZWN0IjoxLCJtaWQiOm51bGwsImFub"
        "255bW91cyI6MCwiZXhwIjoxNjI4MjM1MjAyLCJncmFudFR5cGUiOjAsImp0aSI6"
        "IjZkNGY2NGZjLTkyZjgtNDk5OC1hMDhiLWE0Y2I5OTc0ZGFmYiIsImNsaWVudF9"
        "pZCI6InVzZXJBcHAifQ.DROlEPFxHZ_NyfVQcCsGwOjurkHdHT5XwhiDi4DkUSA";


    commentDto=await recommendedTopics(5,10, "/appuser/web/feed/pullTopicList");
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body:Wrap(
        children:
        List.generate(10, (i) {
          double w = 50.0 + 10 * i;
          return Container(
            color: Colors.primaries[i],
            height: 50,
            width: w,
            child: Text('$i'),
          );
        }),
      ),
    );
  }
}

